# import ast
# import asyncio
# import json
# import os
#
# from dotenv import load_dotenv
# from langchain_core.messages import HumanMessage
# from tortoise.contrib.fastapi import register_tortoise
#
# from entity.database.mysql import History
# from utils.database_connector import DatabaseConnector
#
# '''
# 通过id查询历史记录
# :param id: 历史记录id
# :return: None 或者 历史记录json字符串
# '''
# async def get_history_by_id(id: int):
#     # db =await DatabaseConnector().get_db()
#     # query = f"SELECT content FROM history WHERE id = {id}"
#     # result = db.run(query)
#     result = await History.get(id=id)
#     return result
#
# # get_history_by_id(1)
#
# async def get_history():
#     # db = await DatabaseConnector().get_db()
#     # query = f"SELECT content FROM history"
#     # result = db.run(query)
#     result=await History.all()
#     return result
#
# '''
# 插入历史记录
# :param content: 历史记录内容
# '''
# async def insert_history(content:str):
#     # db =await DatabaseConnector().get_db()
#     # query = f"INSERT INTO history (content,created_time,updated_time) VALUES ('{content}',now(),now())"
#     # result = db.run(query)
#     await History.create(content=content)
#
#
# # async def main():
# #     # human_message = HumanMessage(content="你好").model_dump_json(include={
# #     #     "content",
# #     #     "type"
# #     # })
# #     # await insert_history(HumanMessage(content="你好"))  # 传入 content 属性
# #     # history = await get_history_by_id(2)
# #     # print(history)
# #     # print(result)
# #     # result = await get_history()
# #     # print(result)
# #
# # if __name__ == "__main__":
# #     asyncio.run(main())
#
